package Coriander::Window::Main;
use strict;
use warnings;
our @ISA = qw(Coriander::Window::MainWindow);


sub windowLoad {
    my $win = shift;
    my @ipad = qw(-ipadx 10 -ipady 10 -padx 10 -pady 10);
    my @fillx = qw(-fill x);
    my @fillboth = qw(-fill both -expand 1);
    
    my $connectionBar = $win->Frame(qw(
        Name            connectionBar
        -height         30
    ))->pack(@fillx, @ipad);
    
    $win->geometry($Coriander::options->get("window.geometry"));
    $win->state('zoomed') if $Coriander::options->get("window.maximize");

    my $newie = Coriander::World->new;
    $win->Button(-command => sub {$win->openWorldEditor($newie) } )->pack;
}

sub windowShow{
    my $win = shift;

    $win->show("Coriander::Window::AddressBook");
}
    
sub windowClose {
    my $win = shift;
    
    $Coriander::options->flush(0);
    if ($win->state eq 'zoomed') {
        $Coriander::options->set("window.maximize", 1);
    } else {
        $Coriander::options->set("window.maximize", 0);
        $Coriander::options->set("window.geometry", $win->geometry);
    }
    $Coriander::options->save;
    
    $win->destroy;
}

sub openWorld {
    my $win = shift;
    my $world = shift;
    my $display = $win->Scrolled("ROText",
        Name        =>  "display0",
        -background =>  $Coriander::options->get("ansi.bg_normal"),
        -foreground =>  $Coriander::options->get("ansi.fg_normal"),
        -insertbackground => $Coriander::options->get('ansi.fg_normal'),
        -scrollbars =>  "oe",
        -font       =>  $Coriander::options->get('font'),
        -wrap       =>  "word"
    )->pack(qw(-fill both -expand 1));
}

sub openWorldEditor {
    my $win = shift;
    my $world = shift;
    
    Coriander::Window::EditWorld->editWorld($win, $world);
}

        
1;